<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div style="margin-top: 60px;margin-left: 30px">
    <div style="display: inline-block;float: left">
        <button id='upload-result' class="layui-btn layui-btn-normal" style="margin-top: 5px"><i class="iconfont">&#xe6c0;</i>  提交结果</button>
    </div>
    <div style="display: inline-block;float: left;line-height:38px;padding-top: 6px">
        <span class="x-red" style="margin-left: 10px;" id="tip">(提交的结果应是csv)</span>
        <span class="x-red" style="margin-left: 10px; display: none;" id="file-name"></span>
    </div>
</div>
<div style="margin-top: 30px;margin-left: 30px;margin-right: 30px">
    <table class="layui-table" id="score_list" lay-filter="score_list">
    </table>
</div>
</body>
<script>

    layui.use(["upload",'table'],function () {
        var table = layui.table;
        //第一个实例
        var tablein = table.render({
            elem: '#score_list'
            ,skin:'line'
            ,url: '/score_list' //数据接口
            ,where:{competition_id:getUrlParam("competitionId"),user_id:util.getLocalStorage("user").userId}
            ,page: {theme:'#1e9fff'} //开启分页
            ,cellMinWidth:48
            ,cols: [[ //表头
                {field: 'score', title: '得分', minWidth:50, align:'center'}
                ,{field: 'time', title: '时间', minWidth:80, align:'center'}
            ]]
            // ,limit: 2
            ,parseData: function(res){ //res 即为原始返回的数据
                console.log(res);
                return {
                    "code": res.status, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
        });
        var upload = layui.upload;
        var layer = layui.layer;
        //upload
        upload.render({
            elem: '#upload-result', //指定元素
            url: '/result_upload',
            accept: 'file',
            data:{competition_id:getUrlParam("competitionId"),user_id:util.getLocalStorage("user").userId},
            choose:function(obj){
                obj.preview(function (index,file,result) {
                    $('#file-name').html(file.name);
                    $('#tip').hide();
                    $('#file-name').show();
                });
            },
            before:function(obj){
                layer.load();
            },
            done: function (res, index, upload) {
                console.log(res);
                layer.closeAll('loading');
                // layer.msg('上传成功',{icon:1, time:msgTime});
                tablein.reload();
            },
            error:function (index, upload) {
                layer.closeAll('loading');
                layer.msg('上传失败',{icon:2, time:msgTime});
            }
        });
    });

</script>
</html>